home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / tplt_alloc.pro < prev    next >
Text File  |  1997-07-08  |  5KB  |  206 lines

  1. ;
  2. ; $Id: tplt_alloc.pro,v 1.7 1997/01/15 03:11:50 ali Exp $
  3. ;
  4. ;  WidTemplate
  5. ;   Sample Class definition file
  6. ;
  7. ; Copyright (c) 1993-1997, Research Systems, Inc.  All rights reserved.
  8. ;
  9. ; MODIFICATION HISTORY
  10. ;       Written by:     Joshua Goldstein,       12/93
  11. ;
  12. ;
  13.  
  14.  
  15. ;
  16. ;  TPLT_Icon
  17. ;
  18. FUNCTION TPLT_Icon
  19.   ;  One should either return 0 (indicates no toolbar icon)
  20.   ;  or a BYTARR(4,32) which will be added to the toolbar.
  21.  
  22.   RETURN, 0
  23. END
  24.  
  25. ;
  26. ;  TPLT_Copy
  27. ;   Copy a tmplt.  2 copy methods:
  28. ;
  29. ;   if( copy != NULL)       { *copy = *ptr; free(ptr); }
  30. ;   else                    { *(copy = malloc(...)) = *ptr; }
  31. ;
  32. PRO TPLT_Copy, Ptr, Copy
  33.     GenCopy, Ptr, Copy
  34. END
  35.  
  36.  
  37. ;
  38. ;  TPLT_Destroy
  39. ;   Release resources for the given tmplt
  40. ;
  41. PRO TPLT_Destroy, Ptr
  42.     GenDestroy, Ptr
  43. END
  44.  
  45.  
  46. ;
  47. ;  TPLT_Event
  48. ;   Event handling routine for a tmplt dialog.   Shares common code
  49. ;   (c.f. widbuild.pro)
  50. ;
  51. PRO TPLT_Event, Event
  52.     MISC_Event, Event, 1    ; constant is Font Offset in Foci (see TPLT_Build)
  53. END
  54.  
  55.  
  56. ;
  57. ;  TPLT_Build
  58. ;   Create a dialog box a tmplt object.  If ptr is nil then
  59. ;   create the object as well.
  60. ;
  61. PRO TPLT_Build, Ptr, ParPtr
  62.  
  63.   COMMON WidEd_Comm
  64.  
  65.     TPLT_Alloc, ParPtr, Ptr               ; Allocate object if necessary
  66.     MgrName = 'WE_TPLT' + STRTRIM(Ptr, 2) ; Create dialog box name
  67.     IF XRegistered(MgrName) THEN RETURN    ; See if it already exists
  68.  
  69.     Title   = GetId(Ptr) + '(Child of ' + GetId(ParPtr) + ')'
  70.     Ptr2Obj, Ptr, Obj
  71.  
  72.     ;   Create dialog box
  73.  
  74.     Base    = WIDGET_BASE(/COLUMN, TITLE=Title, GROUP_LEADER=TopDlg)
  75.  
  76. ;****************OBJECT SPECIFIC CODE TO BUILD DIALOG BOX**************
  77. ;   Foci    = LONARR(6)
  78. ;   Base1   = WIDGET_BASE(Base, /FRAME, /COLUMN)
  79. ;   Lab     = WIDGET_LABEL(Base1, VALUE="Basic Information")
  80. ;   Foci(0) = Field(Base1, "Tmplt Text:", Obj.Value, 'VALUE', SIZE=50, /STRING)
  81. ;    Base2   = WIDGET_BASE(Base1,/ROW)
  82.  
  83. ;***************See TPLT_Event for use of the Font Index***************
  84. ;    Foci(1) = Field(Base2, "Font:", Obj.Font, 'FONT', SIZE=50, /STRING)
  85. ;    IF !Version.OS NE 'Win32' AND !Version.OS NE 'MacOS' THEN $
  86. ;       XFontBtn    = WIDGET_TPLT(Base2, VALUE="XFont", UVALUE="XFONT")
  87. ;
  88. ;   Base1   = WIDGET_BASE(Base, /FRAME)
  89. ;   BuildOther, Base, Obj, Foci, 2, /FRAME
  90. ;   Lab     = WIDGET_LABEL(Base1, VALUE="Tmplt Appearance Controls")
  91. ;   BuildXY, Base1, Obj, Foci, 3, /SIZE, /OFFSET
  92. ;   BuildOkCancel, Base, Obj
  93.  
  94. ;****************DECLARE DIALOG INFORMATION**********************
  95.     DlgInfo     = { $
  96.         Foci:       Foci, $     ; Required
  97.         ObjPtr:     Ptr, $      ; Required
  98.         SpecialData: 0b $       ; Data for Dialog Box (widget ids, etc.)
  99.     }
  100.     Obj.Dialog  = Base
  101.     WIDGET_CONTROL, Base, SET_UVALUE=DlgInfo, /NO_COPY
  102.     WIDGET_CONTROL, Base, /REALIZE
  103.     XMANAGER, MgrName, Base, EVENT_HANDLER='TPLT_Event', CLEANUP='MISC_Kill'
  104.     Obj2Ptr, Obj, Ptr
  105. END
  106.  
  107.  
  108. ;
  109. ;  TPLT_Save
  110. ;   Save tmplt information to a file.
  111. ;   This is a simple object to save.
  112. ;
  113. PRO TPLT_Save, Unit, Ptr
  114.     GenWrite, Unit, Ptr
  115. END
  116.  
  117.  
  118. ;
  119. ;  TPLT_Restore
  120. ;   Read in a tmplt object from a file
  121. ;
  122. PRO TPLT_Restore, Unit, Parent, Ptr
  123.     MISC_Restore, Unit, Parent, Ptr, "TPLT", 0
  124. END
  125.  
  126.  
  127. ;
  128. ;  TPLT_Generate
  129. ;   Create a tmplt object for previewing
  130. ;
  131. PRO TPLT_Generate, Base, Ptr
  132.  
  133.   COMMON WidEd_Comm
  134.  
  135.     Ptr2Obj, Ptr, Obj
  136.     Id  = 0L            ; Prevent EXECUTE from creating a new variable
  137.  
  138.     ;   Build a command string
  139.  
  140.     Cmd = 'Id = WIDGET_TPLT(Base'
  141.     SAddCmd, Cmd, Obj.TemplateStringData, 'STRING_KEYWORD'
  142.     IAddCmd, Cmd, Obj.TemplateIntData, 'ANOTHER_KEYWORD'
  143.     SAddCmd, Cmd, Obj.TemplateFont, 'FONT'
  144.  
  145.     ; Create tmplt by executing the command string we just built
  146.  
  147.     Obj2Ptr, Obj, Ptr
  148.  
  149.     IF EXECUTE(Cmd+')') NE 1 THEN BEGIN
  150.         MESSAGE,'Could not create Tmplt ' + VarName(Ptr)
  151.     ENDIF
  152. END
  153.  
  154.  
  155. ;
  156. ;  TPLT_GenWid
  157. ;   Create IDL code for creating a TPLT
  158. ;
  159. PRO TPLT_GenWid, Unit, Ptr, Parent
  160.  
  161.     Name    = VarId(Ptr)            ; Get name for tmplt
  162.     Ptr2Obj, Ptr, Obj               ; Get object information
  163.  
  164.     XPRINTF, Unit, FORMAT='("  ",A," = CW_TPLT( ",A )', /NO_EOL, $
  165.         Name, Parent
  166.     SSaveCmd, Unit, Obj.TemplateFont, "FONT"
  167.     SSaveCmd, Unit, Obj.TemplateStringData, "STRING_KEYWORD"
  168.     ISaveCmd, Unit, Obj.TemplateIntData, "ANOTHER_KEYWORD"
  169.     SSaveCmd, Unit, UValue(Obj, Ptr), "UVALUE"
  170.     XPRINTF, Unit, ')'
  171.  
  172.     Obj2Ptr, Obj, Ptr
  173. END
  174.  
  175. ;  Alloc function must be last function in file
  176.  
  177. ;
  178. ;  TPLT_Alloc
  179. ;       Allocate a <THING> object.
  180. ;
  181. PRO TPLT_Alloc, Parent, Ptr
  182.   COMMON WidEd_Comm
  183.  
  184.     IF KEYWORD_SET(Ptr) NE 0 THEN RETURN    ; if(ptr != NULL) return;
  185.  
  186.     Ptr = WIDGET_BASE(GROUP=TopDlg)         ; Make a pointer
  187.  
  188.     ;   Make a Tmplt object
  189.  
  190.     Obj = {                     $
  191.         WE_TPLT,               $ ; Nice but not required
  192.         Type:           'TPLT',$ ; Set to function prefix
  193.         Parent:         Parent, $ ; Pointer to parent
  194.         Id:             NewId(),$ ; Permanent Id
  195.         Dialog:         0L,     $ ; Ptr to Control Panel (Base widget ID)
  196.         Next:           0L,     $ ; index of next child/free/top
  197.         Name:           '',     $ ; object name
  198.         UValue:         '',     $ ; Required.
  199.         TemplateStringData: '', $ ; Per class information <Sample>
  200.         TemplateIntData: 0,     $ ; Per class information <Sample>
  201.         TemplateFont:   ''      $ ; Per class information <Font Sample>
  202.     }
  203.  
  204.     Obj2Ptr, Obj, Ptr
  205. END
  206.